<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script type="text/javascript" src="<?php echo Yii::app()->baseUrl?>/js/jquery.js"></script>
        <style>
            .mytitle{
                display: none;
            }
            .register{
                margin-top: 30px;
            }
            table{
                border-collapse:collapse;
                border-spacing:0;
                border-left:1px solid #000000;
                border-top:1px solid #000000;
                background: #FFFFFF;
            }
            th,td{
                border-right:1px solid #000000;
                border-bottom:1px solid #000000;
/*                padding:5px 15px;*/
                text-align: center;
            }
            th{
                font-weight:bold;
                background: #66cccc;
            }
            .table_css{
                border-style:none;
            }
            .table_css_1{
                border-style:none;
                width: 50%;
                text-align: right;                
            }  
            .table_css_2{
                border-style:none;
                width: 50%;
                text-align: left;
            }             
        </style>  
        <script>
            //创建
            function click_create(date){
//                window.location.href="/xinhe_item/index.php/activityDetail/create?date="+date;
                window.location.href="<?php echo Yii::app()->baseUrl?>/index.php/activityDetail/create?date="+date;
                
            }
            //查询
            function select(){
                var year=$("#selectYear").val();
                var month=$("#selectMonth").val();
                var week =$("#selectWeek").val();
//                window.location.href="/xinhe_item/index.php/activity/select?year="+year+"&month="+month+"&week="+week; 
                window.location.href="<?php echo Yii::app()->baseUrl?>/index.php/activity/select?year="+year+"&month="+month+"&week="+week;
            }
            //创建
            function select_now(){
                //window.location.href="/xinhe_item/index.php/activity/selectNow"; 
//                window.location.href="/xinhe_item/index.php/activity/clander"; 
                window.location.href="<?php echo Yii::app()->baseUrl?>/index.php/activity/clander";
            } 
            //更新
            function update(id){
                if(id){
//                   window.location.href="/xinhe_item/index.php/activityDetail/update/"+id; 
                   window.location.href="<?php echo Yii::app()->baseUrl?>/index.php/activityDetail/update/"+id;
                }
            }
        </script>  
    </head>
    <body>
        <select id="selectYear" onchange="onchange()"></select>
        <select id="selectMonth">
            <option value="1">1月</option>  
            <option value="2">2月</option> 
            <option value="3">3月</option>
            <option value="4">4月</option> 
            <option value="5">5月</option> 
            <option value="6">6月</option>
            <option value="7">7月</option> 
            <option value="8">8月</option> 
            <option value="9">9月</option> 
            <option value="10">10月</option>
            <option value="11">11月</option>
            <option value="12">12月</option>
        </select>
        <select id="selectWeek">
            <option value="1">第一周</option>
            <option value="2">第二周</option>
            <option value="3">第三周</option>
            <option value="4">第四周</option>
            <option value="5">第五周</option>
        </select>
        <button type="button" onclick="select()">搜 索</button>
        <button type="button" onclick="select_now()">返回今天</button>
        <span id="year" style="display: none;" ><?php echo $year; ?></span>
        <span id="month" style="display: none;" ><?php echo $month; ?></span>
        <span id="week" style="display: none;" ><?php echo $week; ?></span>
        
        <div style="width:100%; margin-top: 1em;">
            <table style=" width: 100%;overflow:auto;">
                <tr style=" height: 30px;">
                    <th style="width:3%; background: #FFFFFF"> </th>
                    <th style="width:15%">活动1</th>
                    <th style="width:15%">活动2</th>
                    <th style="width:15%">活动3</th>
                    <th style="width:15%">活动4</th>
                    <th style="width:15%">活动5</th>
                    <th style="width:15%">活动6</th>
                </tr>
            </table>
            <table style=" width: 100%;overflow:auto;">
                <?php 
                    foreach ($weeks as $keys=>$values){
                        $date= date("d",strtotime($values)); 
                    ?>
                    <tr>
                        <td style="width:3%; background: #66cccc; height: 100px; text-align: center;"><?php echo $date; ?>号</td>
                         <?php
                            $models=  ActivityDetail::model()->findAll("begins like '".$values."%'");
                            $count=  count($models);                           
                            foreach ($models as $key => $value){
                                $connection = Yii::app()->db;
                                $sql="SELECT (count(*)+ (SELECT COUNT(*) FROM party WHERE is_from!=3 AND ad_id=".$value->id.")) as 'count' FROM children  WHERE party_id in (SELECT id FROM party WHERE is_from!=3 AND ad_id=".$value->id.")";
//                                $sql = "SELECT count(*) as count FROM party  WHERE is_from!=3 AND ad_id = ".$value->id;
                                $command_1 = $connection->createCommand($sql);  
                                $result_1 = $command_1->queryAll();  
                                $num_1=$result_1[0]['count'];      
                                $sql="SELECT (count(*)+ (SELECT COUNT(*) FROM party WHERE is_from!=3 AND is_float=1 AND ad_id=".$value->id.")) as 'count' FROM children  WHERE party_id in (SELECT id FROM party WHERE is_from!=3 AND is_float=1 AND ad_id=".$value->id.")";
//                                $sql = "SELECT count(*) as count FROM party  WHERE is_from!=3 AND is_float=1 AND ad_id = ".$value->id;
                                $command_2 = $connection->createCommand($sql);  
                                $result_2 = $command_2->queryAll();  
                                $num_2=$result_2[0]['count']; 
                            ?>
                        <td style="width:15%" onclick="update(<?php echo $value->id; ?>)">
                            <div>
                                <table class="table_css" style="width: 100%">
                                        <tr>
                                            <td colspan="2" class="table_css">
                                                <span style="font-size: 1.5em; font-weight: bold;"><?php echo $value->activity->title; ?></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" class="table_css">
                                                <span style="font-size: 1em; color: #FF0000;">
                                                    <?php 
                                                    if($value->is_float==0){
                                                        echo '闭馆';
                                                    }else if($value->is_float==1){
                                                        echo '开馆';
                                                    }else if($value->is_float==2){
                                                        echo '团体';
                                                    }else if($value->is_float==3){
                                                        echo '报名已满';
                                                    }
                                                    ?>
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" class="table_css">
                                                <span style="font-size: 1.2em;"><?php echo date("H:i:s",strtotime($value->clander_start));?> -- <?php echo date("H:i:s",strtotime($value->clander_end)); ?></span>   
                                            </td>                                           
                                        </tr>
                                    <?php
                                       $model_line = LineDetail::model()->findAll("ad_id=".$value->id);
                                       $line_i=1;
                                       foreach ($model_line as $key => $value_line){
                                        ?>
                                        <tr>
                                            <td class="table_css_1">
                                                <image style=" vertical-align: middle; max-height: 20px; margin-right: 30px;" src="<?php echo Yii::app()->baseUrl;?>/images/u48.png"/>   
                                            </td>
                                            <td class="table_css_2">
                                                <span><?php echo $value_line->car->code; ?></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="table_css_1">
                                                <image style=" vertical-align: middle; max-height: 20px; margin-right: 30px" src="<?php echo Yii::app()->baseUrl;?>/images/u56.png"/>
                                            </td>
                                            <td class="table_css_2">
                                                <span><?php echo $value_line->car->driver; ?></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="table_css_1">
                                                <image style=" vertical-align: middle; max-height: 20px; margin-right: 30px" src="<?php echo Yii::app()->baseUrl;?>/images/u220.jpg"/>
                                            </td>
                                            <td class="table_css_2">
                                                <span><?php echo $value_line->go_time; ?></span>
                                            </td>
                                        </tr>                                           
                                        <tr>
                                            <td class="table_css_1">
                                                <image style=" vertical-align: middle; max-height: 20px; margin-right: 30px" src="<?php echo Yii::app()->baseUrl;?>/images/u66.png"/>
                                            </td>
                                            <td class="table_css_2">
                                                <span><?php echo $value_line->position->address; ?></span>  
                                            </td>
                                        </tr>                         
                                    <?php
                                        if($line_i>2){
                                            echo '<tr><td colspan="2" class="table_css">...</td></tr>';
                                            break;
                                        }
                                        $line_i+=1;
                                       }
                                    ?>
                                        <tr>
                                            <td colspan="2" class="table_css" style="height: 50px;" >
                                                <span style=" margin-top:30px;">
                                                <?php
                                                    if($value->astrict<=$num_1 || $value->is_float==3){
                                                    ?>
                                                    <span style=" margin-top:30px;font-weight: bold; font-size: 13px;">报名已满</span>
                                                    <span style=" margin-top:30px; color: red"><?php echo $num_2.'/'; ?></span>  
                                                    <span style=" margin-top:30px; margin-left: -5px; color: #0090ff"><?php echo $num_1.'/'; ?></span>  
                                                    <span style=" margin-top:30px; margin-left: -5px; font-size: 15px;"><?php echo $value->astrict; ?></span>  
                                                    <?php
                                                    }  else {
                                                        ?>
                                                    <span style=" margin-top:30px;font-weight: bold; font-size: 13px;">报名未满</span>
                                                    <span style=" margin-top:30px; color: red"><?php echo $num_2.'/'; ?></span>  
                                                    <span style=" margin-top:30px; margin-left: -5px; color: #0090ff"><?php echo $num_1.'/'; ?></span>  
                                                    <span style=" margin-top:30px; margin-left: -5px; font-size: 16px;"><?php echo $value->astrict; ?></span>  
                                                    <?php
                                                    }
                                                ?>
                                            </td>
                                        </tr>
                                  </table>   
                                </div>
                            </td>
                            <?php
                            }
                            for($i=$count;$i<6;$i++){
                            ?>
                            <td style="width:15%" onclick="click_create('<?php echo $values;?>')"><image style=" max-height: 25px;" src="<?php echo Yii::app()->baseUrl;?>/images/u44.png"></td>
                            <?php
                            }
                         ?>
                    </tr>
                <?php
                    }
                ?>
            </table> 
        </div>
	<script language="javascript">	
        var year = $("#year").html();
        var month = parseInt($("#month").html(),10);
        var week = $("#week").html();
        /**
         * 年
         */
	var startYear=2015;//起始年份

	var endYear=new Date().getUTCFullYear()+1;//结束年份，默认为当前年份
        
	var obj=document.getElementById('selectYear')

	function onload(){
            for (var i=startYear;i<=endYear;i++)obj.options.add(new Option(i+"年",i));
            var index=0;
            for(var i=startYear;i<=endYear;i++){
                if(year==i){
                   obj.options[index].selected=true; 
                }
                index+=1;
            }
	}
        onload();
        /**
         * 月
         */        
        var mon = document.getElementById("selectMonth");
	//
        mon.options[month-1].selected=true;
        /**
         * 周
         */
        var selectWeek = document.getElementById("selectWeek");
        selectWeek.options[week-1].selected=true;
	</script>              
    </body>
</html>
  <?php 
        if(Yii::app()->user->getFlash('delete_success')){
        echo "<script>art.dialog({icon:'succeed',content:'删除成功！',time:1});</script>";
        }          
    ?> 
